<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="java.util.Date, java.net.URLEncoder" %>

<%@ include file="../includes/header.jspf" %>

<% final Logger log = Logger.getLogger("JSP.DLOAD");%>
<div style="padding: 5px 0px 0px 0px;">
<%
	String port = "",
	        strFOrS = "",
	        strCatType = "",
	        strMainCat = "",
	        strCatID = "",
                strRockvilleGsm="03331234567",
	        strContentId = ""; // Holds the ContentID
	boolean isRockville = false; //to check if the user is from rockville
	
	strContentId = request.getParameter("cid")!=null?request.getParameter("cid").toString():"";
	//String strThisPageName="dload.jsp";
	
        String strPageTitle_thisCat=strContentId;
	     //String strPageTitle_thisCat="Download "+strAppCatType+" "+cid;
	
	strParentCatId=""+strCatID;
	//--out.println("chech IP in rockville :="+strIP);
	if ("124.109.48.196".equals(strIP) || "192.168.222.102".equals(strIP)|| "127.0.0.1".equals(strIP)){
	    isRockville = true;
	}
%>
<%@ include file="../includes/navigationLinks_Purchase.jspf" %>
<%	
	if (isTableSupport) {
	%><table class="tblCat" style="width:100%;" align="center" border="0" cellpadding="0" cellspacing="0" >
    <tr align="center" valign="top">
        <td  align="center" valign="top">
	<%
	}
	%>
	<div  align="center" style="position: relative;width:100%; padding: 10px 0px 15px 0px;">
    <%
	String img = "";
	String txt = "";
	String pr = "";
	String contentType = "";
	String categoryId = "";
	String description = "";
                            

	try {
	    v = wpb.getContentDetails(strContentId);
	    if (v.size() < 1) {
	        out.print("<h3>No Data available!.</h3>");
	        return;
	    } else {
	        try {
	            img = ((Vector) v.get(0)).get(0).toString();
	        } catch (Exception ex) {
	        }//get  contetndimage
	        try {
	            txt = ((Vector) v.get(0)).get(1).toString();
	        } catch (Exception ex) {
	        }//get  contetndimage
	        try {
	            pr = ((Vector) v.get(0)).get(2).toString();
	        } catch (Exception ex) {
	        }//get  contetndimage
	        try {
	            contentType = ((Vector) v.get(0)).get(3).toString();
	        } catch (Exception ex) {
	        }//get contentType
	        try {
	            categoryId = ((Vector) v.get(0)).get(4).toString();
	        } catch (Exception ex) {
	            categoryId = "0";
	        }//get contentType
	        try {
	            description = ((Vector) v.get(0)).get(5).toString();
	        } catch (Exception ex) {
	            description = "";
	        }//get Description
	    }
	} catch (Exception ex) {
	    ex.printStackTrace();
	}

	if (img == null || img.equalsIgnoreCase("null") || img.length() < 3) {
    	%><span class="PortalText"><%=txt%></span><br/><br/><%
	} 
	else {
    	%><div style="padding-bottom: 5px;">
        <img alt="" src="<%=context_Path%>/imgsrv?img=<%=img%>&s=0&w=<%=iconSize%>"/>
        <br/>
        <span class="PortalText"><%=description%></span>
        <br/>
        </div>
	<%
    }

	int pce = 0;
	try {
	    pce = Integer.parseInt(pr.trim());
	} catch (Exception e) {
		pce = 0;
	}
	
	boolean dbCheck = false; // check for the compability in DB
	boolean isSupported = false;
	String queryToBeExecuted = "";
	
	if (contentType.equalsIgnoreCase("POLYTONES")) {
	    if (device.getCapability("mmf").trim().equalsIgnoreCase("true")) {
	        isSupported = true;
	    } else if (device.getCapability("ringtone_midi_polyphonic").trim().equalsIgnoreCase("true")) {
	        isSupported = true;
	    } else if (device.getCapability("sp_midi").trim().equalsIgnoreCase("true")) {
	        isSupported = true;
	    } else if (Integer.parseInt(device.getCapability("voices")) >= 4) {
	        isSupported = true;
	    }
	} else if (contentType.equalsIgnoreCase("TRUETONES")) {
	    if (device.getCapability("ringtone_mp3").trim().equalsIgnoreCase("true")) {
	        isSupported = true;
	    } else if (device.getCapability("ringtone_amr").trim().equalsIgnoreCase("true")) {
	        isSupported = true;
	    } else if (device.getCapability("mp3").trim().equalsIgnoreCase("true")) {
	        isSupported = true;
	    } else if (device.getCapability("amr").trim().equalsIgnoreCase("true")) {
	        isSupported = true;
	    }
	} else if (contentType.equalsIgnoreCase("WALLPAPERS")) {
	    isSupported = true;
	} else if (contentType.equalsIgnoreCase("ANIMATIONS") || contentType.equalsIgnoreCase("ANIMATED")) {
	    isSupported = true;
	} else if (contentType.equalsIgnoreCase("GAME")) {
	    dbCheck = true;
	    queryToBeExecuted = "GETGT";
	} else if (contentType.equalsIgnoreCase("THEMES")) {
	    dbCheck = true;
	    queryToBeExecuted = "GETGT";
	} else if (contentType.equalsIgnoreCase("SCREENSAVERS")) {
	    dbCheck = true;
	} else if (contentType.equalsIgnoreCase("VIDEOS")) {
	    if (device.getCapability("playback_3gpp").trim().equalsIgnoreCase("true")) {
	        isSupported = true;
	    }
	}
	
	if (dbCheck) {	
	    HashMap hm = new HashMap();
	    hm.put("contentID", strContentId);
	    hm.put("categoryID", categoryId);
	    hm.put("brand", strBrand);
	    hm.put("model", strModel);
	
	    v = wpb.execCustomQuery(queryToBeExecuted, hm);
	    if (v.size() > 0) {
	        isSupported = true;
	    }	
	    v = null;
	}
	
	port = wpb.getShortCodeOnPrice(pce);
	
	if (isSupported && !port.isEmpty()) {
		%>
		<div style="padding-bottom: 5px;">
		<a class="service_link" href="sms:<%=port%>?body=<%=strContentId%>">Click Here</a> and you will get Download link in your Messaging Inbox</div>		
		<div class="divStepTop">Content Charges: <b>Rs. <%=pr%>+tax</b></div>
		<div style="padding-bottom: 5px;">If Download link doesn't work, SMS "<b><%=strContentId%></b>" (to -->) <b><%=port%></b></div>		
		<%
                try{
                if(isRockville){
                 wpb.saveDownload(strContentId, strRockvilleGsm, "", "", "0", "ROCKVILLE");   
                 Vector vec = wpb.getContentDownloadParams(strContentId, categoryId, contentType, strRockvilleGsm);
                %>		
		<div class="divStepTop">Content Charges Rs. <%=pr%></div>
		<div style="padding-top: 10px;">
                    <form action="<%=context_Path%>/downloader" method="post">
			<input type="hidden" name="brand" value="<%=strBrand%>" />
			<input type="hidden" name="model" value="<%=strModel%>" />
			<input type="hidden" name="msisdn" value="<%=strRockvilleGsm%>" />
                        <%
                            for (int i = 0; i < vec.size(); i++) {
                                String name = vec.get(i++).toString();
                                String value = vec.get(i).toString();
                         %>
                         <input type="hidden" name="<%=name%>" value="<%=value%>" />
                        <%       
                            }
                        %>
                        <input type="submit" name="submit" class="input" value=" Download ">
		</form>
		</div>
		 <%}
                               }catch(Exception e){
                                   log.error("Prepare Link to Download From Rockville IP",e);
                               }
                %>
                
	<%
	} //end. if supported
	else {
		%><div class="divStepTop">Requested content not supported on your handset.</div><%
	}
	%>
	</div>
    <%
    if (isTableSupport) {
    	%></td>
        </tr></table><%
	}
	%>
</div>

<div style="padding:0px 0px 0px 0px;text-decoration: underline;">
        <jsp:include page="../banner.jsp">
            <jsp:param name="w" value="<%=width%>"/>
        </jsp:include>
</div>
<%@ include file="../includes/footer.jspf"%>


<%
wpb.LogVisit(strIP, thisPage,strGsm,strApn, strBrand, strModel, app, request.getQueryString());
%>